package com.yunsc.shop.controller.order;

import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.order.dto.CheckoutOrderDTO;
import com.yunsc.order.sevice.CheckoutOrderService;
import com.yunsc.order.vo.CheckoutOrderVO;
import com.yunsc.shop.utils.ClientInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:  订单-结算接口
 * @date: 2024-05-12 14:02
 */
@Api(tags = "订单-生成")
@RestController
@RequestMapping("/checkout")
public class CheckoutController {


    @Resource
    private CheckoutOrderService checkoutOrderService;

    @Resource
    private ClientInfoUtils clientInfoUtils;


    @ApiOperation(value = "/api/checkout/order", tags = "获取订单结算数据")
    @GetMapping("/order")
    public Result<?> processCheckoutOrder(CheckoutOrderDTO params) {
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        Integer storeId = clientInfoUtils.getCurrentStoreId();
        CheckoutOrderVO checkoutOrder = checkoutOrderService.checkoutOrder(params, userId, storeId);
        return Result.ok(checkoutOrder);
    }

    @ApiOperation(value = "/api/checkout/order/submit", tags = "提交订单")
    @PostMapping("/submit")
    public Result<?> checkoutOrderSubmit(@RequestBody CheckoutOrderDTO params) {
        Integer userId = SecurityUtil.getCurrentUserIdEx();
        Integer storeId = clientInfoUtils.getCurrentStoreId();
        String platform = clientInfoUtils.getCurrentPlatform();
        Integer orderId = checkoutOrderService.checkoutOrderSubmit(params, userId, storeId, platform);
        Map<String, Object> result = new HashMap<>();
        result.put("orderId", orderId);
        return Result.ok(result);
    }





}
